package web

import (
	"strconv"
)

type Response struct {
	Data  interface{} `json:"data"`
	Error error       `json:"error"`
}

type tuner struct {
	PPM float64 `json:"ppm"`
	DFR float64 `json:"dfr"`
}

func strFint(str string, f func(float64) float64) int {
	ffc, err := strconv.ParseFloat(str, 64)
	if err == nil {
		return int(f(ffc))
	} else {
		return 0
	}
}

func Str1int(str string) int  { return strFint(str, func(x float64) float64 { return x }) }
func Str10int(str string) int { return strFint(str, func(x float64) float64 { return x * 10. }) }
func Str2int(str string) int {
	i, err := strconv.ParseInt(str, 10, 32)
	if err != nil {
		return 0
	} else {
		return int(i)
	}
}
